package model.dao;

import java.util.ArrayList;
import java.util.Date;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import model.bean.Ambiente;
import model.bean.Dispositivo;
import model.bean.Evento;
import model.bean.Participante;
import model.factory.HibernateUtil;
import model.interfaces.IEvento;

public class EventoDAO implements IEvento {

	private Session session;

	@Override
	// correto
	public void cadastraEvento(Evento evento) {
		try {
			session = HibernateUtil.getSession();
			Transaction tx = session.beginTransaction();
			session.saveOrUpdate(evento);
			tx.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	
	
	@Override
	// correto
	public void removeEventoByNome(String nomeEvento) {
		session = HibernateUtil.getSession();
		Transaction tx = session.beginTransaction();
		String hql = " DELETE FROM Evento e WHERE e.nome LIKE :nomeEvento ";
		Query q = session.createQuery(hql);
		q.setString("nomeEvento", nomeEvento);
		q.executeUpdate();
		tx.commit();
	}
	
	@Override
	public void removerEventoPeloId(int idEvento) {
		session = HibernateUtil.getSession();
		Transaction tx = session.beginTransaction();
		String hql = " DELETE FROM Evento e WHERE e.eventoId = :idEvento ";
		Query q = session.createQuery(hql);
		q.setInteger("idEvento", idEvento);
		q.executeUpdate();
		tx.commit();
		
	}

	@Override
	public Evento findEventoById(int idEvento) {
		session = HibernateUtil.getSession();
		Query q = session.createQuery("FROM Evento e WHERE e.eventoId = :idEvento");
		q.setInteger("idEvento", idEvento);
		return (Evento) q.uniqueResult(); 
	}



	@Override
	public void insereParticipanteEmEvento(Participante participante,
			Evento evento) {
		// TODO Auto-generated method stub
		
	}



	@Override
	public void vinculaAmbienteEvento(Ambiente ambiente, Evento evento) {
		// TODO Auto-generated method stub
		
	}

}
